import 'package:bilibili_getx_project/core/I18n/str_res_keys.dart';
import 'package:bilibili_getx_project/core/shared_preference/shared_preference_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:get/get.dart';

import '../../shared/app_theme.dart';
import '../../shared/asset_image.dart';
import 'main_logic.dart';

class MainView extends StatelessWidget {
  final logic = Get.find<MainLogic>();
  final state = Get.find<MainLogic>().state;
  static String routeName = "/";

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainLogic>(
      builder: (logic) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: IndexedStack(
            index: state.currentIndex,
            children: state.mainIndexStackPage,
          ),
          bottomNavigationBar: BottomNavigationBar(
            selectedFontSize: 13.sp,
            unselectedFontSize: 12.sp,
            selectedItemColor: AppTheme.norMainThemeColor,
            type: BottomNavigationBarType.fixed,
            items: [
              buildBottomNavigationBarItem(icon: "home", label: SR.home.tr),
              buildBottomNavigationBarItem(icon: "dynamic", label: SR.dynamic.tr),
              buildBottomNavigationBarCenterItem(),
              buildBottomNavigationBarItem(icon: "mall", label: SR.mall.tr),
              buildBottomNavigationBarItem(icon: "mine", label: SR.mine.tr),
            ],
            currentIndex: state.currentIndex,
            onTap: (i){
              logic.exchangeBottomNavigationBar(i);
            },
          ),
          floatingActionButton: SpeedDial(
            children: [
              SpeedDialChild(
                child: Icon(Icons.abc),
                onTap: () {
                  logic.exchangeLanguage();
                },
              ),
            ],
          ),
        );
      },
    );
  }

  buildBottomNavigationBarCenterItem() {
    return BottomNavigationBarItem(
      icon: Container(
        margin: EdgeInsets.only(top: 12.r),
        padding: EdgeInsets.all(5.r),
        decoration: BoxDecoration(
          color: AppTheme.norMainThemeColor,
          borderRadius: BorderRadius.circular(10.r)
        ),
        width: 34.r,
        height: 34.r,
        child: Image.asset(AssetsImage.addCustomPNG),
      ),
      label: ""
    );
  }

  buildBottomNavigationBarItem({required String icon, required String label}) {
    return BottomNavigationBarItem(
      icon: SizedBox(
        width: 20.r,
        height: 20.r,
        child: Image.asset("assets/image/${icon}_custom.png"),
      ),
      label: label,
      activeIcon: SizedBox(
        width: 20.r,
        height: 20.r,
        child: Image.asset("assets/image/${icon}_selected.png"),
      ),
    );
  }
}
